route.js 988 B

123456789101112131415161718192021222324252627282930313233343536
  1. // app/api/branches/[branch]/years/route.js
  2. import { NextResponse } from "next/server";
  3. import { listYears } from "@/lib/storage";
  4. /**
  5. * GET /api/branches/[branch]/years
  6. *
  7. * Returns the list of year folders for a given branch.
  8. * Example: /api/branches/NL01/years → { branch: "NL01", years: ["2023", "2024"] }
  9. */
  10. export async function GET(request, ctx) {
  11. // Next.js 16: params are resolved asynchronously via ctx.params
  12. const { branch } = await ctx.params;
  13. console.log("[/api/branches/[branch]/years] params:", { branch });
  14. // Basic validation of required params
  15. if (!branch) {
  16. return NextResponse.json(
  17. { error: "branch Parameter fehlt" },
  18. { status: 400 }
  19. );
  20. }
  21. try {
  22. const years = await listYears(branch);
  23. return NextResponse.json({ branch, years });
  24. } catch (error) {
  25. console.error("[/api/branches/[branch]/years] Error:", error);
  26. return NextResponse.json(
  27. { error: "Fehler beim Lesen der Jahre: " + error.message },
  28. { status: 500 }
  29. );
  30. }
  31. }